//
//  YATaskGameGetGameServerList.m
//  YoucApi
//
//  Created by Liam on 11/13/12.
//
//

#import "YATaskGameGetGameServerList.h"
#import "YAObjGameServer.h"

@implementation YATaskGameGetGameServerList

TASK_AUTO_REGISTER(TaskGameGetGameServerList);

- (NSString *)_getUriParamA
{
	return @"get_gameserver_list";
}

- (void)_dealWithJSONResponse:(id)responseObject withError:(NSError *)error
{
	YARespGameServerList *respGameServerList = [[[YARespGameServerList alloc] initWithError:error context:self.context] autorelease];
	
	NSMutableArray *list = nil;
	
	if ([error code] == YoucApiErrorSuccess)
	{
		list = [NSMutableArray array];
        
		NSArray *jsonList = (NSArray *)responseObject;
		for (NSDictionary *item in jsonList)
		{
			YAObjGameServer *server = [[[YAObjGameServer alloc] init] autorelease];
			server.serverName = SAFE_STRING([item objectForKey:KEY_SERVERNAME]);
			server.serverTime = [SAFE_STRING([item objectForKey:KEY_SERVERTIME]) doubleValue];
			server.platformName = SAFE_STRING([item objectForKey:KEY_PLATFORMNAME]);
			server.platformUrl = SAFE_STRING([item objectForKey:KEY_PLATFORMURL]);
			server.gameUrl = SAFE_STRING([item objectForKey:KEY_GAMEURL]);
			[list addObject:server];
		}
	}
	
	respGameServerList.list = list;
    
	if ([self.delegate respondsToSelector:@selector(getGameServerListResponse:respGameServerList:)])
	{
		[self.delegate getGameServerListResponse:self respGameServerList:respGameServerList];
	}
}

@end
